import Vue from 'vue'
import Vuex from 'vuex'
import {
	isLogin
} from "@/access/common.js"

Vue.use(Vuex)
const cartNum = uni.getStorageSync('cartNum') || 0
const cartPrice = uni.getStorageSync('cartPrice') || 0
if (cartNum > 0) {
	uni.setTabBarBadge({
		index: 2,
		text: cartNum
	});
}
const store = new Vuex.Store({
	state: {
		nowAddress: {},
		distributionTextSet: '',
		businessmanId: '',
		staffId: '',
		hasLogin: !!uni.getStorageSync('token'),
		user_address: {},
		cateModel: 4,
		cartNum: cartNum,
		cartPrice: cartPrice,
		enterpriseInfo: {}, // 获取企业详情
		baseSet: uni.getStorageSync('baseSet') || {
			themeStyle: {
				label: '热情红',
				theme: 'red',
				color_t: '#ff3883',
				color_o: '#fd463e',
			}
		},
		locationObj: uni.getStorageSync('locationObj') ? JSON.parse(uni.getStorageSync('locationObj')) : {},
		userStatus: uni.getStorageSync('userStatus'),
		distributionSet: {}, // 分销商设置
		iosAuditStatus: 5 //判断IOS是否审核通过，因为IOS审核必须要账号密码登录，4为审核中，跳账号密码登录页面，5已通过审核，跳微信登录页面
	},
	getters: {
		showPrice: state => {
			return state.hasLogin;
		}
	},
	mutations: {
		// 获取企业详情
		commit_enterpriseInfo(state, detail) {
			state.enterpriseInfo = detail
			uni.setStorageSync('enterpriseInfo', detail)
		},
		// 设置默认地址
		commit_nowAddress(state, nowAddress) {
			state.nowAddress = nowAddress
		},
		// 分销文字设置
		commit_distributionTextSet(state, stateTextSet) {
			state.distributionTextSet = stateTextSet
		},
		// 设置分销商上级ID
		commit_businessmanId(state, businessmanId) {
			state.businessmanId = businessmanId
		},
		// 设置指定业务员ID
		commit_staffId(state, staffId) {
			state.staffId = staffId
		},
		// 分销商基础设置
		commit_distributionSet(state, distributionSet) {
			state.distributionSet = distributionSet
		},
		// 判断登录状态
		commit_hasLogin(state, hasLogin) {
			state.hasLogin = hasLogin
		},
		// IOS提交APPstore审核状态
		commit_iosAuditStatus(state, sttaus) {
			state.iosAuditStatus = sttaus
		},
		// 用户信息
		commit_userStatus(state, obj) {
			state.userStatus = obj
			uni.setStorageSync('userStatus', obj)
		},
		// 当前定位
		commit_locationObj(state, obj) {
			state.locationObj = obj
			uni.setStorageSync('locationObj', JSON.stringify(obj))
		},
		// 商城基础设置信息
		commit_baseSet(state, obj) {
			state.baseSet = obj
			uni.setStorageSync('baseSet', obj)
		},
		// 分类页面模版
		commit_cateModel(state, obj) {
			state.cateModel = obj
		},
		// 用户地址
		commit_address(state, obj) {
			state.user_address = obj
		},
		commit_cartNum(state, num) {
			state.cartNum = num
			uni.setStorageSync('cartNum', cartNum)
		},
		commit_cartPrice(state, price) {
			// console.log('price',price)
			state.cartPrice = price
			uni.setStorageSync('cartPrice', price)
		},
		logout(state) {
			state.hasLogin = false;
			state.userStatus = {};
			uni.removeStorage({
				key: 'userStatus'
			})
		}
	},
	actions: {

	}
})

export default store
